﻿using System;
using System.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Mono.Cecil;

namespace NDasm.Core.UI.Tree
{
    public class TypeNodeViewModel : MemberNodeViewModel
    {
        private static BitmapImage glyph = new BitmapImage(new Uri("/NDasm.Core;component/Resources/typeGlyph.png", UriKind.Relative));

        public TypeNodeViewModel(TypeDefinition typeDefinition, string scope)
            : base(typeDefinition, scope)
        {
            FillMethods();
        }          

        public override ImageSource Glyph
        {
            get { return glyph; }
        }

        private void FillMethods()
        {
            var typeDefinition = (TypeDefinition)Member;
            children.Clear();
            foreach(TypeDefinition type in typeDefinition.NestedTypes.OrderBy(t => t.Name))
                children.Add(new TypeNodeViewModel(type, scope));
            foreach (MethodDefinition method in typeDefinition.Methods.OrderBy(m => m.Name))
                children.Add(new MethodNodeViewModel(method, scope));
        }
    }
}
